import type { PageParams, PageResult, PageApi } from '@/types/global'
import type {
  BannerItem,
  CategoryItem,
  BulletinItem,
  GuidePaperItem,
  KnowledgeItem,
  QuestionItem,
  HandpickedBookItem,
  SponsorItem,
  OnlyIdItem,
  ExaminationPaperItem,
  ExaminationMenuItem,
  ExerciseKnowledgepointItem,
  ExercisePaperItem,
  YearMonthItem,
  QuestionVideoPermitItem,
  VideoItem,
  PaymentItem,
} from '@/types/home'
import {
  http,
  http_login,
  http_object,
  http_object_data,
  http_data_results_list,
  http_object_list,
  http_last_data,
  http_data_results_not_list,
} from '@/utils/http'
import type { LoginResult } from '@/types/member'
/**首页-公告-小程序 */
export const getBulletinAPI = () => {
  return http<BulletinItem>({
    method: 'GET',
    url: '/BulletinModelViewSet/get_bulletin/',
  })
}

/**首页-广告区域-小程序 */
export const getHomeBannerAPI = () => {
  return http<BannerItem>({
    method: 'GET',
    url: `/SwiperImageModelViewSet/get_swiper_image/`,
  })
}

/** 首页-前台分类-小程序 */
export const getHomeCategoryAPI = () => {
  return http<CategoryItem>({
    method: 'GET',
    url: '/CategoryModelViewSet/get_category/',
  })
}

/** 首页-热门推荐-小程序 */
export const getHomeHotAPI = () => {
  // return http<HotItem[]>({
  return http({
    method: 'GET',
    url: '/home/hot/mutli',
  })
}

/** 猜你喜欢-小程序 */
export const getHomeGoodsGuessLikeAPI = (data?: PageParams) => {
  // return http<PageResult<GuessItem>>({
  return http({
    method: 'GET',
    url: '/home/goods/guessLike',
    data,
  })
}
// 导学案API的参数
type guidePaperParams = {
  id: number
  paper_type: number
  page?: number
  size?: number
}
/**获取导学案-小程序 */
export const getGuidePaperAPI = (data?: guidePaperParams) => {
  return http<GuidePaperItem>({
    method: 'GET',
    url: '/GuidePaperModelViewSet/knowledgepoint/',
    data,
  })
}
type subjectParams = {
  subject_id: number
}
/** 获取知识点-小程序 */
export const getKnowledgeAPI = (data?: subjectParams) => {
  return http<KnowledgeItem>({
    method: 'GET',
    url: '/knowledgepoints/get_knowledge_by_subject/',
    data,
  })
}
/**获取练习知识点简洁版- 小程序 */
export const getExerciseKnowledgeAPI = (data?: subjectParams) => {
  return http_last_data<ExerciseKnowledgepointItem>({
    method: 'GET',
    url: '/knowledgepoints/get_knowledge_by_subject_id_for_exercise/',
    data,
  })
}
type exercisePaperParams = {
  subject_id: number
  year?: string
  month?: string
}
/**获取某个学科下的所有试卷，用于练习显示简洁版的标题- 小程序 */
export const getExercisePaperAPI = (data?: exercisePaperParams) => {
  return http_last_data<ExercisePaperItem>({
    method: 'GET',
    url: '/ExaminationPaperViewSet/get_paper_by_subject_and_year_month_for_exercise/',
    data,
  })
}
/**获取年月列表，用于练习页面左侧年月折叠列表- 小程序 */
export const getYearMonthAPI = () => {
  return http_last_data<YearMonthItem>({
    method: 'GET',
    url: '/ExaminationPaperViewSet/get_year_month/',
  })
}
type PaperParams = {
  paper_id: number
  page: number
  size: number
}
/** 根据试卷id获取题目-小程序 */
export const getQuestionByPaperAPI = (data?: PaperParams) => {
  return http<QuestionItem>({
    method: 'GET',
    url: '/GetQuestionsByPaper/',
    data,
  })
}
// 根据知识点获取题目的参数
type knowledgeParams = {
  knowledge_id: number
  page: number
  size: number
}
/** 根据知识点id获取题目-小程序 */
export const getQuestionByKnowledgeAPI = (data?: knowledgeParams) => {
  return http<QuestionItem>({
    method: 'GET',
    url: '/questions/get_question_by_knowledge/',
    data,
  })
}
/**获取题目-小程序 */
export const getQuestionNoAuthAPI = () => {
  return http<QuestionItem>({
    method: 'GET',
    url: '/questions/no_auth/',
  })
}
/** 获取甄选教辅-小程序 */
export const getHandpickedBookAPI = () => {
  return http<HandpickedBookItem>({
    method: 'GET',
    url: '/BookModelViewSet/get_book/',
  })
}
/** 获取捐款-小程序 */
export const getSponsorAPI = () => {
  return http<SponsorItem>({
    method: 'GET',
    url: '/SponsorModelViewSet/get_sponsor_record/',
  })
}
/** 发送每日一签-小程序 */
export const postDailySignatureAPI = () => {
  return http_login<LoginResult>({
    method: 'POST',
    url: '/DailySignatureAPIView/',
  })
}

/** 提交一个题目到指定的试卷 */
export const postOneQuestionToExamPaperAPI = (data: object) => {
  return http_object_data<Object>({
    method: 'POST',
    url: '/ExaminationPaperViewSet/add_one_question/',
    data,
  })
}
/** 获取当前用户申请过的试卷，且未过期-小程序 */
export const getAppliedPaperAPI = () => {
  return http_object<number>({
    method: 'GET',
    url: '/ExaminationPaperViewSet/has_applied_paper/',
  })
}
/** 获取当前用户申请过且批准的试卷，且未过期-小程序 */
export const getAppliedAndApprovedPaperAPI = () => {
  return http_object<number>({
    method: 'GET',
    url: '/ExaminationPaperViewSet/has_applied_and_approved_paper/',
  })
}
/** 获取可修改的试卷，且未过期-小程序 */
export const getRevisablePaperAPI = (data: object) => {
  return http<ExaminationPaperItem>({
    method: 'GET',
    url: '/ExaminationPaperViewSet/get_revisable_paper/',
    data,
  })
}
/** 提交用户申请试卷解析的权限 */
export const postPermitAPI = (data: object) => {
  return http_object_data<Object>({
    method: 'POST',
    url: '/PermitExplainPaperOfUserModelViewSet/create_permit/',
    data,
  })
}
/**获取某份试卷中自己录入的试题 */
export const getPaperOwnerQuestionAPI = (data: object) => {
  return http<QuestionItem>({
    method: 'GET',
    url: '/questions/get_question_by_examination_owner/',
    data,
  })
}
/** 提交用户申请试卷解析的权限 */
export const postOcrAPI = (data: object) => {
  return http_object_data<Object>({
    method: 'POST',
    url: '/ImageOcrAPIView/',
    data,
  })
}
/** 请求获取试卷 */
export const getExaminationPaperMenuListAPI = () => {
  return http_last_data<ExaminationMenuItem>({
    method: 'GET',
    url: '/GetPaperMenuByDateAndGrade/',
  })
}
type subjectKnowledgeItem = {
  value: string
  name: string
  childrenL: any[]
}
/** 请求所有学科的知识点，结果是二级嵌套数组 */
export const getSubjectKnowledgeAPI = () => {
  return http_last_data<subjectKnowledgeItem>({
    method: 'GET',
    url: '/knowledgepoints/get_knowledge_all_subject_for_upload_guide_paper/',
  })
}
/** 上传导学案 */
export const postGuidePaperFileAPI = (data: object) => {
  return http_last_data<object>({
    method: 'POST',
    url: '/GuidePaperModelViewSet/',
    data,
  })
}
/** 上传导学案后扣款 */
export const postGuidePaperFeiAPI = (data: object) => {
  return http_last_data<object>({
    method: 'POST',
    url: '/PaymentAmountWithDownloadPaperApiView/',
    data,
  })
}
/**获取练习题目，参数为知识点和是否已做 */
export const getExerciseQuestionWithKnowledgepointAPI = (data: object) => {
  return http_last_data<QuestionItem>({
    method: 'GET',
    url: '/questions/get_question_filter_knowledge_and_has_done/',
    data,
  })
}
/**获取练习题目，参数为知识点和是否已做 */
export const getExerciseQuestionWithExaminationPaperAPI = (data: object) => {
  return http_last_data<QuestionItem>({
    method: 'GET',
    url: '/ExaminationPaperViewSet/get_question_filter_paper_and_has_done/',
    data,
  })
}

type WrongQuestionItem = {
  add_time: string
  question_info: QuestionItem
}
/**获取自己名下的错题本,没有参数 */
export const getAllWrongQuestionMyselfNoPageAPI = () => {
  return http_last_data<WrongQuestionItem>({
    method: 'GET',
    url: '/questions/get_wrong_no_page_myself/',
  })
}
/**获取自己名下的错题本,参数为页码和页尺寸 */
export const getAllWrongQuestionMyselfAPI = (data: object) => {
  return http_last_data<WrongQuestionItem>({
    method: 'GET',
    url: '/questions/get_wrong_for_owner/',
    data,
  })
}

/**获取错题的id列表 */
export const getAllWrongQuestionIdAPI = () => {
  return http_last_data<number>({
    method: 'GET',
    url: '/questions/get_all_wrong_question_id_for_owner/',
  })
}

/**发送收集错题请求 */
export const postCollectWrongQuestionAPI = (data: object) => {
  return http_last_data<number>({
    method: 'POST',
    url: '/questions/create_wrong_question_return_id_list/',
    data,
  })
}
/**发送取消错误收集 */
export const postUnCollectWrongQuestionAPI = (data: object) => {
  return http_last_data<number>({
    method: 'DELETE',
    url: '/questions/cancel_wrong_question_return_id_list/',
    data,
  })
}
/**发送已做题目请求 */
export const postHasDoQuestionAPI = (data: object) => {
  return http_last_data<number>({
    method: 'POST',
    url: '/UserDoQuestionLogModelViewSet/create_question_has_done_owner/',
    data,
  })
}
/**读取已做题目请求 */
export const getHasDoQuestionAPI = () => {
  return http_last_data<number>({
    method: 'GET',
    url: '/UserDoQuestionLogModelViewSet/get_question_has_done_owner/',
  })
}
/**读取试题视频申请列表请求 */
export const getQuestionVideoPermitAPI = (data: object) => {
  return http_last_data<QuestionVideoPermitItem>({
    method: 'GET',
    url: '/questions/get_permit_question_video/',
    data,
  })
}
/** 提交用户申请试卷视频解析的权限 */
export const postQuestionVideoPermitAPI = (data: object) => {
  return http_object_data<Object>({
    method: 'POST',
    url: '/questions/create_permit_question_video/',
    data,
  })
}
/**读取试题视频申请列表请求 */
export const getHasUploadVideoAPI = () => {
  return http_last_data<number>({
    method: 'GET',
    url: '/VideoModelViewSet/get_video_question_list_owner/',
  })
}

/**读取七牛云的token */
export const getQINIUTokenAPI = (data: object) => {
  return http_data_results_not_list<string>({
    method: 'POST',
    url: '/QINIUTokenAPIView/',
    data,
  })
}

/**读取所有自己的微视频 */
export const getMyVideoListAPI = (data: object) => {
  return http_data_results_list<VideoItem>({
    method: 'GET',
    url: '/VideoModelViewSet/get_video_list_owner',
    data,
  })
}

/**发送给后台播放视频后的支付费用和播放记录 */
export const postPlayVideoAPI = (data: object) => {
  return http_data_results_not_list<string>({
    method: 'POST',
    url: '/UserPlayVideoLogModelViewSet/create_video_has_played_log',
    data,
  })
}

/**获取自己的收支列表，参数是分支类型和分页 */
export const getMyPaymentListAPI = (data: object) => {
  return http_data_results_list<PaymentItem>({
    method: 'GET',
    url: '/BankPointLogModelViewSet/get_income_expense_for_owner',
    data,
  })
}
/**发送给后台反馈 */
export const postFeekbackAPI = (data: object) => {
  return http_data_results_not_list<string>({
    method: 'POST',
    url: '/FeedbackViewSet',
    data,
  })
}
/**获取自己的资料 */
export const getMyselfDataAPI = () => {
  return http_data_results_not_list<LoginResult>({
    method: 'GET',
    url: '/UserModelViewSet/myself_info',
  })
}
